home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 685 / publicmanager / publicmanager.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  44KB  |  1,206 lines

  1. /*
  2.  *    © 1992 by Michael Watzl, written with DICE: dcc PublicManager -2.0 -proto -o publicmanager
  3.  */
  4.  
  5. #include <exec/memory.h>
  6. #include <graphics/displayinfo.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/screens.h>
  10. #include <libraries/gadtools.h>
  11. #include <workbench/startup.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <libraries/asl.h>
  14. #include <stdlib.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/gadtools_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <clib/icon_protos.h>
  23. #include <clib/asl_protos.h>
  24. #include <clib/diskfont_protos.h>
  25.  
  26. #define    TMPSIZE 512L            /* memory that will be allocated for temp stuff */
  27. #define TOOLNUM 20            /* Maximal number of tools */
  28.  
  29. #define MENU_PROJ_PALETTE    0
  30. #define    MENU_PROJ_ABOUT        1
  31. #define    MENU_PROJ_SAVE          2
  32. #define    MENU_PROJ_QUIT          3
  33. #define MENU_PROJ_UPSCREEN      4
  34. #define MENU_PROJ_UPMODES       5
  35. #define MENU_PROJ_BACKDROP      6
  36.  
  37. #define MENU_MODE_DEFAULT       10
  38. #define    MENU_MODE_SHANGHAI      11
  39. #define    MENU_MODE_POPUP         12
  40.  
  41. #define MENU_MODE_NTSCHIRES    13
  42. #define    MENU_MODE_NTSCHIRESLACE 14
  43. #define    MENU_MODE_PALHIRES      15
  44. #define MENU_MODE_PALHIRESLACE  16
  45. #define    MENU_MODE_PRODUCTIVITY  17
  46. #define    MENU_MODE_CUSTOM    18
  47.  
  48. #define MENU_MODE_NOOSCAN    20
  49. #define MENU_MODE_TEXTOSCAN    21
  50. #define MENU_MODE_STDOSCAN    22
  51.  
  52. #define MENU_MODE_DEPTH1    30
  53. #define MENU_MODE_DEPTH2        31
  54. #define MENU_MODE_DEPTH3    32
  55. #define MENU_MODE_DEPTH4    33
  56.  
  57. #define MENU_MODE_WBFONT    40
  58. #define MENU_MODE_TOPAZ        41
  59. #define MENU_MODE_DISKFONT    42
  60.  
  61. #define MENU_MODE_SIZE          43
  62.  
  63. #define MENU_TOOLS_BASE        50
  64.  
  65. #define    PALETTESIGNAL        (1<<palwin->UserPort->mp_SigBit)
  66. #define    WINDOWSIGNAL        (1<<window->UserPort->mp_SigBit)
  67. #define    PUBLICSIGNAL        NULL /*(1<<publicsignal)*/
  68.  
  69. #define    FHEIGHT            screen->Font->ta_YSize
  70.  
  71. #define    PALGAD        0
  72. #define    REDGAD          1
  73. #define    GREENGAD    2
  74. #define    BLUEGAD        3
  75. #define    OKGAD        4
  76. #define WBGAD        5
  77. #define    CANCELGAD       6
  78.  
  79. #define    WBFONT        0
  80. #define    TOPAZ           1
  81. #define DISKFONT        2
  82.  
  83. /*
  84.  *    PublicScreen configuration structure
  85.  */
  86. struct ScreenConfig {
  87.     WORD    SizeX,SizeY;            /* Size of this Public Screen */
  88.         WORD    Depth;                /* Depth (Number of Bitplanes */
  89.     ULONG    DisplayID;            /* DisplayMode, look at your includes for more info! */
  90.         UWORD    Overscan;
  91.     UWORD   PubMode;            /* This may be SHANGHAI, POPPUBSCREEN */
  92.     WORD    Font;                /* This can be WBFONT, TOPAZ or DISKFONT */
  93.     struct     TextAttr    textattr;    /* the TextAttr, which is used for this screen */
  94.     BOOL    Default;
  95.     BOOL    Backdrop;            /* Backdrop window or not? */
  96.     BOOL    Tools;                /* Is there any configuration file? */
  97. };
  98.  
  99.  
  100. /*
  101.  *    Prototypes
  102.  */
  103. STRPTR    strcpy( STRPTR dest, STRPTR source );
  104. STRPTR    strncpy( STRPTR dest, STRPTR source , WORD length );
  105. STRPTR    strcat( STRPTR dest, STRPTR source );
  106. ULONG    strlen( STRPTR str );
  107. WORD    sprintf( STRPTR dest, STRPTR format, ...);
  108. STRPTR    strstr( STRPTR text , STRPTR findme );
  109.  
  110. VOID    main( VOID );
  111. VOID    quit( STRPTR Text );
  112.  
  113. VOID    ReOpen( VOID );
  114. BOOL    OpenScr( VOID );
  115. BOOL    CloseScr( VOID );
  116. VOID    OpenWin( VOID );
  117. VOID    CloseWin( VOID );
  118. VOID    OpenPalette( VOID );
  119. VOID    ClosePalette( VOID );
  120.  
  121. VOID    About( VOID );
  122. VOID    SetScreenColors( VOID );
  123. VOID    Update( VOID );
  124. LONG    GetCustomID( VOID );
  125. LONG    GetNewSize( VOID );
  126.  
  127. WORD    usermessage( STRPTR text );
  128. LONG    pix(STRPTR text);
  129. ULONG    ahex2ulong( STRPTR ahex );
  130. WORD    c2hex( WORD ch  );
  131. WORD    hex2c( WORD hex );
  132. VOID    getcolor( WORD index , struct Screen *s);
  133.  
  134.  
  135. /*
  136.  *    Static Data
  137.  */
  138. static    UBYTE *VersTag ="\0Public Manager V1.2 © 1992 by Michael Watzl";
  139.  
  140. const    STRPTR    FontTTString[]     = {"WB","TOPAZ"};
  141. const    UWORD    PenData[]     = {~0};
  142. const    STRPTR  OpenScrError[]     = {"No error","The required monitor is not available!","You need ECS for this mode!","Not enough memory!","Not enough chip memory","This public screen already exists!","This displaymode is unknown!"};
  143. const    STRPTR    OscanString[]     = {"NO","TEXT","STANDARD"};
  144.  
  145. /*
  146.  *    Global Data
  147.  */
  148. struct    IntuitionBase     *IntuitionBase;
  149. struct    Library        *GadToolsBase;
  150. struct     Library        *UtilityBase;
  151. struct    Library        *IconBase;
  152. struct    Library        *GfxBase;
  153. struct    Library        *AslBase;
  154. struct    Library        *DiskFontBase;
  155. struct    Screen        *screen, *s;
  156. struct    Window        *window, *palwin;
  157. struct    Menu        *menu, *toolsmenu;
  158. struct    NewMenu        *toolnm=NULL;
  159. struct    DimensionInfo    dimensioninfo;
  160. struct    MenuItem    *def_mitem, *sha_mitem, *pop_mitem;
  161. struct    Gadget        *palcon, *gad[ 7 ];
  162. struct    DiskObject      *mydob=NULL;
  163. struct    FontRequester    *fontrequester;
  164. struct    TextFont    *textfont;
  165. struct  TextExtent    textextent;
  166. struct    EasyStruct    easymessage = {sizeof(struct EazyStruct),0,"Public Manager Message", NULL , "Ok" };    /* Easy Reqs */
  167. UBYTE    FontName[32];
  168. ULONG    ScrError=NULL;
  169. UBYTE    Name[129]="AutoPublic";
  170. UBYTE    FileName[129];
  171.  
  172. UBYTE    ToolType[ TOOLNUM ][ 64 ];
  173. UBYTE    Tool[ TOOLNUM ][64];
  174.  
  175. UBYTE    ColorChars[49];
  176. UBYTE    myname[64];
  177. VOID    *vi;
  178. WORD    col0[3][16];                    /* saved colors, for canceling the palette */
  179. UWORD    r,g,b;                        /* actual Colors (for Palette) */
  180. WORD    activegad=0;                    /* I need this for the palette (slidergads) */
  181. STRPTR    temp;                        /* will be allocated */
  182. struct    ColorSpec    colors[17] = {/* COL0 */ 0, 10, 10, 10, /* COL1 */ 1,  0,  0, 2,  /* COL2 */ 2, 14, 14, 14, /* COL3 */ 3, 15, 11, 16, /* END */ -1};
  183. struct  ScreenConfig    sc        = { 640 , 200 , 2 , HIRES_KEY , OSCAN_TEXT , NULL , TOPAZ , FontName     , 0 , 0 , FPF_ROMFONT | FPF_DISKFONT , FALSE , TRUE },
  184.             defaultsc = { 640 , 200 , 2 , HIRES_KEY , OSCAN_TEXT , NULL , TOPAZ , "topaz.font" , 8 , 0 , FPF_ROMFONT | FPF_DISKFONT , FALSE , TRUE };
  185. struct    TagItem SliderItem[] = {
  186.     GA_FollowMouse,        TRUE,
  187.     GTSL_Min,        0,
  188.     GTSL_Max,        15,
  189.     GTSL_Level,        0,
  190.     GTSL_LevelFormat,    "%2.2ld",
  191.     GA_RelVerify,        TRUE,
  192.     GA_Immediate,        TRUE,
  193.     GTSL_MaxLevelLen,    2,
  194.     GTSL_LevelPlace,    PLACETEXT_RIGHT,
  195.     STRINGA_Font,        &sc.textattr,
  196.     TAG_END
  197. };
  198.  
  199. VOID
  200. wbmain(struct WBStartup* wbmsg)
  201. {
  202.         BPTR old,new;
  203.         WORD i;
  204.  
  205.     if(!( temp = AllocMem( TMPSIZE , MEMF_PUBLIC )))    exit(0);
  206.     if(!( toolnm = (struct NewMenu *)AllocMem( sizeof(struct NewMenu) * TOOLNUM , MEMF_PUBLIC | MEMF_CLEAR )))    quit( NULL );
  207.  
  208.     if(!(IconBase=(struct IconBase*)OpenLibrary("icon.library",0)))    exit(0);
  209.     if(!(UtilityBase=(struct UtilityBase*)OpenLibrary("utility.library",37))) quit(NULL);
  210.  
  211.         old = CurrentDir( wbmsg->sm_ArgList->wa_Lock );
  212.  
  213.     strcpy( myname , wbmsg->sm_ArgList->wa_Name);
  214.     if(!( mydob = GetDiskObjectNew( myname )))    quit(NULL);
  215.  
  216.     UnLock(new);
  217.  
  218.         strncpy( temp, FindToolType( mydob->do_ToolTypes , "NAME"), 79 );
  219.         if( strlen(temp) ) strcpy( Name , temp );
  220.  
  221.     strncpy( temp , FindToolType( mydob->do_ToolTypes , "DISPLAYID" ), 79 );
  222.     if(strlen( temp ) == 10) sc.DisplayID = ahex2ulong( temp );
  223.  
  224.     strcpy( temp , FindToolType( mydob->do_ToolTypes , "DEPTH" ) );
  225.     if( strlen(temp) != 0) sc.Depth = atoi( temp );
  226.  
  227.     strcpy( temp , FindToolType( mydob->do_ToolTypes , "SIZEX" ));
  228.     if( strlen(temp) != 0) sc.SizeX = atoi( temp );
  229.  
  230.     strcpy( temp , FindToolType( mydob->do_ToolTypes , "SIZEY" ));
  231.     if( strlen(temp) != 0) sc.SizeY = atoi( temp );
  232.  
  233.     sc.Default  = (BOOL)FindToolType( mydob->do_ToolTypes , "DEFAULT"  );
  234.         if( FindToolType( mydob->do_ToolTypes , "POP"      ) ) sc.PubMode  = POPPUBSCREEN;
  235.         if( FindToolType( mydob->do_ToolTypes , "SHANGHAI" ) ) sc.PubMode |= SHANGHAI;
  236.     sc.Backdrop = (BOOL)FindToolType( mydob->do_ToolTypes , "BACKDROP" );
  237.     strcpy( temp , FindToolType( mydob->do_ToolTypes , "FONT" ) );
  238.          if( Stricmp( temp , FontTTString[0] ) == 0)    sc.Font = WBFONT ;
  239.     else if( Stricmp( temp , FontTTString[1] ) == 0)    sc.Font = TOPAZ  ;
  240.     else {
  241.                 sc.Font = DISKFONT;
  242.         strncpy( FontName , temp , strstr( temp , ",") - temp );
  243.         sc.textattr.ta_YSize = atoi( strstr(temp,",")+1 );
  244.     }
  245.         strncpy( temp, FindToolType( mydob->do_ToolTypes , "OSCAN" ) , 79 );
  246.         if( Stricmp( temp , "TEXT" ) == 0 )           sc.Overscan = OSCAN_TEXT;
  247.         if( Stricmp( temp , "STD" ) == 0 )           sc.Overscan = OSCAN_STANDARD;
  248.         if( Stricmp( temp , "NO" ) == 0 )        sc.Overscan = NULL;
  249.      strncpy( ColorChars , FindToolType( mydob->do_ToolTypes , "COLORS") , 48 );
  250.      strncpy( FileName , FindToolType( mydob->do_ToolTypes , "CONFIG" ) , 128 );
  251.     sc.Tools=TRUE;
  252.     main();
  253. }
  254.  
  255. VOID
  256. main( VOID )
  257. {
  258.     struct    MenuItem     *mi;
  259.     struct    IntuiMessage    *msg;
  260.     ULONG   waitsig, signal;
  261.     UWORD    leave=FALSE;
  262.     WORD    i;
  263.         UWORD    index=1;
  264.     BPTR     old;
  265.     ULONG    OldClass;
  266.     WORD     x=0;
  267.  
  268.     if(mydob == NULL ){
  269.         PutStr("Please start me from WB!\n");
  270.         exit(10);
  271.     }
  272.  
  273.     if(!(GfxBase      =OpenLibrary("graphics.library",0L)))        exit(5);
  274.     if(!(IntuitionBase=OpenLibrary("intuition.library",37L)))    quit(NULL);
  275.     if(!(GadToolsBase = OpenLibrary("gadtools.library",37L)))    quit("No gadtools.library available");
  276.     if(!(AslBase      = OpenLibrary("asl.library"     , 0L)))    quit("No asl.library available");
  277.  
  278.     if(!( OpenScr() ))    quit(NULL);
  279.  
  280.     waitsig = WINDOWSIGNAL;
  281.         FOREVER{
  282.             signal = Wait( waitsig );
  283.         if(signal & WINDOWSIGNAL)
  284.         {
  285.                 while(msg = GT_GetIMsg( window->UserPort ))
  286.             {
  287.                 if(msg->Class==IDCMP_CLOSEWINDOW){
  288.                     GT_ReplyIMsg( msg );
  289.                     while( msg = GT_GetIMsg( window->UserPort )) GT_ReplyIMsg( msg );
  290.                                     msg=NULL;
  291.                     if( CloseScr() )    quit(NULL);
  292.                 }
  293.                 if(msg->Class==IDCMP_MENUPICK){
  294.                     mi = ItemAddress(menu,msg->Code);
  295.                                     switch( GTMENUITEM_USERDATA(mi)){
  296.                     case MENU_PROJ_BACKDROP:
  297.                         GT_ReplyIMsg( msg );
  298.                         while( msg = GT_GetIMsg( window->UserPort )) GT_ReplyIMsg( msg );
  299.                                         msg=NULL;
  300.                         CloseWin();
  301.                                                 sc.Backdrop = !sc.Backdrop;
  302.                                                 OpenWin();
  303.                         break;
  304.                     case MENU_PROJ_PALETTE:
  305.                         OpenPalette();
  306.                         waitsig = WINDOWSIGNAL | PALETTESIGNAL;
  307.                         break;
  308.                                     case MENU_PROJ_ABOUT:
  309.                                     About();
  310.                                     break;
  311.                     case MENU_PROJ_SAVE:
  312.                         x=0;
  313.                                             ColorChars[0]='\0';
  314.                         for( i=0 ; i< 16 ; i++ ){
  315.                             getcolor(i, screen);
  316.                             ColorChars[0+i*3] = hex2c( r );
  317.                             ColorChars[1+i*3] = hex2c( g );
  318.                             ColorChars[2+i*3] = hex2c( b );
  319.                         }
  320.                         ColorChars[ 48 ]='\0';
  321.                         if( Name     ){    strcpy( ToolType[ x ] , "NAME=");
  322.                                                                 strcat( ToolType[ x ] , Name);
  323.                                                 }
  324.                                                 sprintf( ToolType[++x],"DISPLAYID=0x%08lx", sc.DisplayID );
  325.                                                 strcpy( ToolType[++x] , "COLORS=" );
  326.                                                 strcat( ToolType[  x] , ColorChars );
  327.                         strcpy( ToolType[++x] , "OSCAN=" );
  328.                         strcat( ToolType[ x ] , OscanString[sc.Overscan] );
  329.                         if( sc.Default  )    strcpy( ToolType[++x] , "DEFAULT"  );
  330.                         if( sc.PubMode & SHANGHAI     == SHANGHAI     )    strcpy( ToolType[++x] , "SHANGHAI" );
  331.                         if( sc.PubMode & POPPUBSCREEN == POPPUBSCREEN )    strcpy( ToolType[++x] , "POP"      );
  332.                         if( sc.Backdrop )  strcpy( ToolType[++x] , "BACKDROP" );
  333.                         strcpy( ToolType[++x] , "FONT="   );
  334.                         if( sc.Font == DISKFONT ){
  335.                             strcat(ToolType[  x],sc.textattr.ta_Name);
  336.                             strcat(ToolType[  x],",");
  337.                             sprintf(temp,"%.4ld",sc.textattr.ta_YSize);
  338.                             strcat(ToolType[  x], temp);
  339.                         } else
  340.                             strcat( ToolType[  x] , FontTTString[ sc.Font ] );
  341.                         strcpy( ToolType[++x] , "DEPTH=" );
  342.                         ToolType[  x][6] = sc.Depth+48;
  343.                         ToolType[  x][7] = '\0';
  344.                         strcpy( ToolType[++x] , "SIZEX=" );
  345.                         sprintf( temp , "%ld" , sc.SizeX );
  346.                         strcat( ToolType[  x] , temp );
  347.  
  348.                         strcpy( ToolType[++x] , "SIZEY=" );
  349.                         sprintf( temp , "%d" , sc.SizeY );
  350.                         strcat( ToolType[  x] , temp );
  351.  
  352.                                                 ToolType[++x][0] = '\0';
  353.                         for( i=0 ; i<x ; i++) mydob->do_ToolTypes[i]=ToolType[i];                            old=CurrentDir( ((struct Process *)FindTask(NULL))->pr_HomeDir ); /* set home dir */
  354.                         PutDiskObject( myname , mydob );
  355.                         CurrentDir(old);
  356.                         break;
  357.                                        case MENU_PROJ_QUIT:
  358.                         GT_ReplyIMsg( msg );
  359.                         while( msg = GT_GetIMsg( window->UserPort )) GT_ReplyIMsg( msg );
  360.                                         msg=NULL;
  361.                         if( CloseScr() )  quit(NULL);
  362.                         break;
  363.                     case MENU_MODE_DEFAULT:
  364.                         sc.Default= !sc.Default;
  365.                         goto smallupdate;
  366.                     case MENU_MODE_SHANGHAI:
  367.                         sc.PubMode &= !(sc.PubMode & SHANGHAI);
  368.                         goto smallupdate;
  369.                     case MENU_MODE_POPUP:
  370.                         sc.PubMode &= !(sc.PubMode & POPPUBSCREEN);
  371. smallupdate:                    Update();
  372.                         break;
  373.                     case MENU_PROJ_UPSCREEN:
  374.                         GT_ReplyIMsg( msg );
  375.                         while( msg = GT_GetIMsg( window->UserPort )) GT_ReplyIMsg( msg );
  376.                         ReOpen();
  377.                         Update();
  378.                         break;
  379.                     case MENU_PROJ_UPMODES:
  380.                         Update();
  381.                         break;
  382.                                         case MENU_MODE_NTSCHIRES:
  383.                         sc.DisplayID = NTSC_MONITOR_ID | HIRES_KEY;
  384.                         goto doit;
  385.                                         case MENU_MODE_NTSCHIRESLACE:
  386.                         sc.DisplayID = NTSC_MONITOR_ID | HIRESLACE_KEY;
  387.                                 goto doit;
  388.                                         case MENU_MODE_PALHIRES:
  389.                         sc.DisplayID = PAL_MONITOR_ID | HIRES_KEY;
  390.                         goto doit;
  391.                                         case MENU_MODE_PALHIRESLACE:
  392.                         sc.DisplayID = PAL_MONITOR_ID | HIRESLACE_KEY;
  393.                         goto doit;
  394.                                         case MENU_MODE_PRODUCTIVITY:
  395.                         sc.DisplayID = VGA_MONITOR_ID | VGAPRODUCT_KEY;
  396.                         goto doit;
  397.                     case MENU_MODE_CUSTOM:
  398.                                                 LONG id;
  399.                         id=GetCustomID();
  400.                         if( id == -1) break;
  401.                         sc.DisplayID=id;
  402.                         goto doit;
  403.                     case MENU_MODE_NOOSCAN:
  404.                         sc.Overscan=NULL;
  405.                         goto doit;
  406.                     case MENU_MODE_TEXTOSCAN:
  407.                         sc.Overscan=OSCAN_TEXT;
  408.                         goto doit;
  409.                     case MENU_MODE_STDOSCAN:
  410.                         sc.Overscan=OSCAN_STANDARD;
  411.                         goto doit;
  412.                     case MENU_MODE_DEPTH1:
  413.                         sc.Depth=1;
  414.                         goto doit;
  415.                     case MENU_MODE_DEPTH2:
  416.                         sc.Depth=2;
  417.                         goto doit;
  418.                     case MENU_MODE_DEPTH3:
  419.                         sc.Depth=3;
  420.                         goto doit;
  421.                     case MENU_MODE_DEPTH4:
  422.                         sc.Depth = 4;
  423.                         goto doit;
  424.                     case MENU_MODE_WBFONT:
  425.                         sc.Font=WBFONT;
  426.                         goto doit;
  427.                     case MENU_MODE_TOPAZ:
  428.                         sc.Font=TOPAZ;
  429. doit:                        GT_ReplyIMsg( msg );
  430.                         while( msg = GT_GetIMsg( window->UserPort )) GT_ReplyIMsg( msg );
  431.                                         msg=NULL;
  432.                         ReOpen();
  433.                         break;
  434.                     case MENU_MODE_DISKFONT:
  435.                         struct TagItem asltag[]={
  436.                             ASL_Window    , window,
  437.                             ASL_Hail    , "Choose a font...",
  438.                             ASL_FontName    , screen->Font->ta_Name,
  439.                             ASL_FontHeight    , screen->Font->ta_YSize,
  440.                             TAG_END};
  441.                                                if( fontrequester=( struct FontRequester *)AllocAslRequest(ASL_FontRequest , asltag))
  442.                         {
  443.                                                        if( AslRequest( fontrequester , asltag ))
  444.                             {
  445.                                 sc.Font = DISKFONT;
  446.                                 strcpy( FontName ,fontrequester->fo_Attr.ta_Name );
  447.                                 sc.textattr.ta_YSize = fontrequester->fo_Attr.ta_YSize;
  448.                                                            FreeAslRequest( fontrequester );
  449.                                 goto doit;
  450.                                                        }
  451.                                                        FreeAslRequest( fontrequester );
  452.                                             }
  453.                         break;
  454.                                        case MENU_MODE_SIZE:
  455.                                         LONG newsize;
  456.                                             newsize = GetNewSize();
  457.                                             if(newsize == -1 ) break;
  458.                                             sc.SizeY = (newsize & 0x0000ffff);        /* lower nibble */
  459.                                             sc.SizeX = (newsize & 0xffff0000) >> 16;    /* upper nibble */
  460.                                             goto doit;
  461.                                                 break;
  462.                     default:
  463.                         if( (WORD)GTMENUITEM_USERDATA(mi) >= MENU_TOOLS_BASE && (WORD)GTMENUITEM_USERDATA(mi)<= MENU_TOOLS_BASE + TOOLNUM ){
  464.                             strcpy( temp , "run ");
  465.                             strcat( temp , Tool[ (WORD)GTMENUITEM_USERDATA(mi)-MENU_TOOLS_BASE ] );
  466.                             Execute( temp , 0 , 0 );
  467.                         }
  468.                                                 break;
  469.                     } /* switch menu */
  470.                                 } /* if menupick */
  471.                                 GT_ReplyIMsg(msg);
  472.                         }
  473.                 } /* WINDOWSIGNAL */
  474.                 if( signal & PALETTESIGNAL)
  475.         {
  476.             leave=FALSE;
  477.             while( leave == FALSE )
  478.             {
  479.                 while( msg = GT_GetIMsg( palwin->UserPort ) )
  480.                 {
  481.                             switch(msg->Class){
  482.                     case IDCMP_CLOSEWINDOW:
  483.                                    leave=TRUE;
  484.                                        break;
  485.                             case IDCMP_VANILLAKEY:
  486.                             switch(msg->Code){
  487.                                 case    'u':
  488. usecolors:                            leave=TRUE;
  489.                                 SetScreenColors();
  490.                                 break;
  491.                                     case    'c':    for(i=0;i<16;i++) SetRGB4( &(screen->ViewPort), i , col0[0][i],col0[1][i],col0[2][i]);
  492.                                 leave=TRUE;
  493.                                 break;
  494.                         case    'w':    goto getwbcols;
  495.                         }
  496.                         break;
  497.                                 case IDCMP_GADGETUP:
  498.                         activegad=0;
  499.  
  500.                         switch(((struct Gadget*)(msg->IAddress))->GadgetID){
  501.                         case PALGAD:
  502.                             index=msg->Code;
  503.                             getcolor(index, screen);
  504.                             break;
  505.                         case REDGAD:
  506.                             r=msg->Code;
  507.                             SetRGB4( &(screen->ViewPort), index , r , g , b );
  508.                             break;
  509.                         case GREENGAD:
  510.                             g=msg->Code;
  511.                             SetRGB4( &(screen->ViewPort), index , r , g , b );
  512.                             break;
  513.                         case BLUEGAD:
  514.                             b=msg->Code;
  515.                             SetRGB4( &(screen->ViewPort), index , r , g , b );
  516.                             break;
  517.                         case WBGAD:
  518. getwbcols:                            if( s = LockPubScreen("Workbench" ) ){
  519.                                                         for( i = 16 ; i>=0; i--){
  520.                                     getcolor( i , s );
  521.                                     SetRGB4( &(screen->ViewPort), i , r , g , b );
  522.                                 }
  523.                                                             UnlockPubScreen(NULL, s );
  524.                                                        } else usermessage("Can't lock wb");
  525.                                                        break;
  526.                                         case CANCELGAD:
  527.                             for(i=0;i<16;i++) SetRGB4( &(screen->ViewPort), i , col0[0][i],col0[1][i],col0[2][i] );
  528.                                     case OKGAD:
  529.                             goto usecolors;
  530.                         } /* end switch GadgetID */
  531.                     case IDCMP_GADGETDOWN:
  532.                         i=(((struct Gadget*)(msg->IAddress))->GadgetID);
  533.                         activegad=i;
  534.                         if(i==1)    r=msg->Code;
  535.                         if(i==2)    g=msg->Code;
  536.                         if(i==3)    b=msg->Code;
  537.                         if(i==1 || i==2 || i==3) SetRGB4( &(screen->ViewPort), index , r , g , b );
  538.                         break;
  539.                     case IDCMP_MOUSEMOVE:
  540.                         if(activegad==1)    r=msg->Code;
  541.                         if(activegad==2)    g=msg->Code;
  542.                         if(activegad==3)    b=msg->Code;
  543.                         if(activegad==1 || activegad==2 || activegad==3) SetRGB4( &(screen->ViewPort), index , r , g , b );
  544.                         break;
  545.                             } /* switch class */
  546.                             GT_ReplyIMsg( msg );
  547.                 } /* while palette msg */
  548.             } /* while leave */
  549.             waitsig = WINDOWSIGNAL; /* only menu IDCPMs */
  550.             ClosePalette();
  551.             } /* pal sig */
  552.     } /* FROEVER */
  553. }
  554.  
  555. BOOL
  556. OpenScr( VOID )
  557. {
  558.     WORD res;
  559.     struct    TagItem    screentag[] = {
  560.         SA_ErrorCode,   &ScrError,
  561.             SA_Depth,    sc.Depth,
  562.             SA_Colors,    colors,
  563.         SA_Font,    &sc.textattr,
  564.         SA_DisplayID,    sc.DisplayID,
  565.             SA_Overscan,    sc.Overscan,
  566.             SA_Pens,        PenData,
  567.         SA_PubName,    Name,
  568.             SA_Type,    PUBLICSCREEN,
  569.         SA_Width,    sc.SizeX,
  570.         SA_Height,    sc.SizeY,
  571.         SA_DClip,    NULL,
  572.         SA_FullPalette,    TRUE,
  573.         SA_AutoScroll,    TRUE,
  574.             TAG_END
  575.     };
  576.     SetScreenColors();
  577.     GetDisplayInfoData( NULL , (UBYTE *)&dimensioninfo , sizeof(struct DimensionInfo), DTAG_DIMS , sc.DisplayID );
  578.     switch( sc.Overscan ) {
  579.     case NULL:
  580.         screentag[11].ti_Data = &dimensioninfo.Nominal;
  581.         break;
  582.     case OSCAN_TEXT:
  583.         screentag[11].ti_Data = &dimensioninfo.TxtOScan;
  584.         break;
  585.     case OSCAN_STANDARD:
  586.         screentag[11].ti_Data = &dimensioninfo.StdOScan;
  587.         break;
  588.     }
  589.     if( sc.SizeX == 0 || sc.SizeX < ((struct Rectangle *)(screentag[11].ti_Data))->MaxX+1 ) screentag[  9 ].ti_Tag = TAG_IGNORE;
  590.     if( sc.SizeY == 0 || sc.SizeY < ((struct Rectangle *)(screentag[11].ti_Data))->MaxY+1 ) screentag[ 10 ].ti_Tag = TAG_IGNORE;
  591.  
  592.     switch(sc.Font)
  593.     {
  594.     case WBFONT:
  595.         if(s=LockPubScreen("Workbench")){
  596.             strcpy( FontName , s->Font->ta_Name );
  597.             sc.textattr.ta_YSize = s->Font->ta_YSize;
  598.             UnlockPubScreen( NULL, s);
  599.         }
  600.         break;
  601.     case TOPAZ:
  602.                 strcpy(FontName,"topaz.font");
  603.         sc.textattr.ta_YSize=8;
  604.         break;
  605.     case DISKFONT:
  606.         break;
  607.     }
  608.     if( ((sc.DisplayID & VGA_MONITOR_ID) == VGA_MONITOR_ID) && (sc.Depth >2) ) sc.Depth=2;
  609.     if(!( textfont = OpenDiskFont( &(sc.textattr) ))) usermessage("WARNING: Couldn't open requested font!");
  610.  
  611. retry:    if(!( screen=OpenScreenTagList(NULL, screentag) ))
  612.     {
  613.         if( ScrError == OSERR_PUBNOTUNIQUE )
  614.         {
  615.             strcat( Name , "." );
  616.                         goto retry;
  617.                 } else
  618.                 {
  619.                         easymessage.es_GadgetFormat = "Retry|Default|Quit";
  620.                     res = usermessage( OpenScrError[ ScrError ] );
  621.             if( res == 1 ) goto retry;
  622.             if( res == 2 ){
  623.                 CopyMem( &defaultsc , &sc , sizeof( struct ScreenConfig ) );
  624.                 if( OpenScr() )    return( TRUE );
  625.             }
  626.                     return( FALSE );
  627.                 }
  628.     }
  629.     easymessage.es_GadgetFormat = "Ok";
  630.  
  631.            if(!( vi = GetVisualInfo(screen, TAG_END)))    quit("Can't get visual info!");
  632.     if( PubScreenStatus(screen, 0L) != 1)    usermessage("WARNING: I was not able to make this screen public!");
  633.     SetPubScreenModes( sc.PubMode );
  634.         if( sc.Default ) SetDefaultPubScreen( Name );
  635.  
  636.     OpenWin();
  637.     return( TRUE );
  638. }
  639.  
  640. BOOL
  641. CloseScr( VOID )
  642. {
  643.     if( screen ){
  644.         ClosePalette();
  645.         CloseWin();
  646.         if( screen->FirstWindow != NULL){
  647.             usermessage( "There are still windows on this screen.\nI can't close it.");
  648.             OpenWin();
  649.             return( FALSE );
  650.         }
  651.         if(screen)    CloseScreen( screen );
  652.         screen   = NULL;
  653.         CloseFont( textfont );
  654.         textfont = NULL;
  655.         if(vi)        FreeVisualInfo( vi );
  656.         vi       = NULL;
  657.     }
  658.     return( TRUE );
  659. }
  660.  
  661.  
  662. VOID
  663. quit( STRPTR text )
  664. {
  665.     if(text)                usermessage( text );
  666.  
  667.     if(!( CloseScr() ))    return;
  668.  
  669.     if( textfont )        CloseFont( textfont );
  670.     if( sc.Default )    SetDefaultPubScreen( "Workbench" );
  671.     if( mydob )        FreeDiskObject( mydob );
  672.     if(GadToolsBase)    CloseLibrary(GadToolsBase);
  673.     if(IntuitionBase)    CloseLibrary((struct Library *)IntuitionBase);
  674.     if(UtilityBase)         CloseLibrary(UtilityBase);
  675.     if(IconBase)        CloseLibrary(IconBase);
  676.     if(GfxBase)        CloseLibrary(GfxBase);
  677.     if(AslBase)        CloseLibrary(AslBase);
  678.     if(DiskFontBase)        CloseLibrary(DiskFontBase);
  679.     if(temp)        FreeMem( temp  , TMPSIZE );
  680.     if( toolnm )        FreeMem( toolnm , sizeof(struct NewMenu) * TOOLNUM );
  681.     exit(0);
  682. }
  683.  
  684. WORD
  685. usermessage( STRPTR text )
  686. {
  687.     UWORD m0;
  688.     easymessage.es_TextFormat = text;
  689.     m0 = SetPubScreenModes( NULL );
  690.     SetPubScreenModes( m0 );
  691.  
  692.     if(!( m0 & POPPUBSCREEN )) ScreenToFront( NULL );
  693.     return( EasyRequest( NULL , &easymessage, NULL,NULL) );
  694. }
  695.  
  696. VOID
  697. OpenPalette( VOID )
  698. {
  699.     BOOL leave=FALSE;
  700.     WORD i=0, index=0, col;
  701.     struct    Gadget *g;
  702.  
  703.     if( palwin ) return;
  704.  
  705.     for( i=0 ; i< 16  ; i++ ){     /* col is only temporary */
  706.         col = GetRGB4( ((struct ViewPort)(screen->ViewPort)).ColorMap , i );
  707.         col0[0][i] = ((col & (0x0f00)) >> 8);
  708.         col0[1][i] = ((col & (0x00f0)) >> 4);
  709.         col0[2][i] =  (col & (0x000f));
  710.         }
  711.  
  712.     i     = 6*pix("CANCEL") + 40;         /* windowwidth  */
  713.     index = FHEIGHT*14;                /* windowheight */
  714.     struct NewGadget palette =    { 10                    , FHEIGHT* 2,  i-20 , FHEIGHT*2 , NULL     , screen->Font , PALGAD    ,NULL           , vi , NULL};
  715.     struct NewGadget rslide  =    { pix("WGreenWW")       , FHEIGHT* 5,  i - rslide.ng_LeftEdge - pix("W00W") -20 , FHEIGHT+4 , "Red"    , screen->Font , REDGAD    ,PLACETEXT_LEFT , vi , NULL};
  716.     struct NewGadget gslide  =    { rslide.ng_LeftEdge    , FHEIGHT* 7, rslide.ng_Width                           , FHEIGHT+4 , "Green"  , screen->Font , GREENGAD  ,PLACETEXT_LEFT , vi , NULL};
  717.     struct NewGadget bslide  =    { rslide.ng_LeftEdge    , FHEIGHT* 9, rslide.ng_Width                           , FHEIGHT+4 , "Blue"   , screen->Font , BLUEGAD   ,PLACETEXT_LEFT , vi , NULL};
  718.     struct NewGadget ok     =    { 10                    , FHEIGHT*11, 2*pix("CANCEL") , FHEIGHT*2 , "_USE"    , screen->Font , OKGAD     , PLACETEXT_IN  , vi , NULL};
  719.     struct NewGadget wb     =    { 20+  ok.ng_Width      , FHEIGHT*11, ok.ng_Width     , FHEIGHT*2 , "_WB"     , screen->Font , WBGAD     , PLACETEXT_IN  , vi , NULL};
  720.     struct NewGadget cancel  =    { 30+2*ok.ng_Width      , FHEIGHT*11, ok.ng_Width     , FHEIGHT*2 , "_CANCEL" , screen->Font , CANCELGAD , PLACETEXT_IN  , vi , NULL};
  721.  
  722.     if(!( palcon           = CreateContext((struct Gadget **)&palcon)))                            leave=TRUE;
  723.     if(!( gad[ PALGAD    ] = CreateGadget(PALETTE_KIND , palcon           ,&palette ,GTPA_Depth,sc.Depth,GTPA_IndicatorWidth,50,TAG_DONE,0)))    leave=TRUE;
  724.     if(!( gad[ REDGAD    ] = CreateGadgetA(SLIDER_KIND , gad[ PALGAD    ] ,&rslide  ,SliderItem)))             leave=TRUE;
  725.     if(!( gad[ GREENGAD  ] = CreateGadgetA(SLIDER_KIND , gad[ REDGAD    ] ,&gslide  ,SliderItem)))             leave=TRUE;
  726.     if(!( gad[ BLUEGAD   ] = CreateGadgetA(SLIDER_KIND , gad[ GREENGAD  ] ,&bslide  ,SliderItem)))             leave=TRUE;
  727.     if(!( gad[ OKGAD     ] = CreateGadget( BUTTON_KIND , gad[ BLUEGAD   ] ,&ok      ,GT_Underscore,'_',TAG_DONE,0))) leave=TRUE;
  728.     if(!( gad[ WBGAD     ] = CreateGadget( BUTTON_KIND , gad[ OKGAD     ] ,&wb      ,GT_Underscore,'_',TAG_DONE,0))) leave=TRUE;
  729.     if(!( gad[ CANCELGAD ] = CreateGadget( BUTTON_KIND , gad[ WBGAD     ] ,&cancel  ,GT_Underscore,'_',TAG_DONE,0))) leave=TRUE;
  730.     if(leave==TRUE){
  731.         FreeGadgets(palcon);
  732.         palcon=NULL;
  733.         return;
  734.     }
  735.     if(!(palwin=(struct Window *)OpenWindowTags(NULL,
  736.         WA_Left        , (screen->Width  - i ) /2,
  737.         WA_Top        , (screen->Height - index ) /2,
  738.         WA_Width    , i ,
  739.         WA_Height    , index ,
  740.         WA_Flags    , WFLG_ACTIVATE | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET,
  741.                 WA_Title    , "Palette Window",
  742.         WA_IDCMP    , IDCMP_CLOSEWINDOW|SLIDERIDCMP|PALETTEIDCMP|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_VANILLAKEY,
  743.         WA_Gadgets    , palcon ,
  744.         WA_PubScreen,        screen,
  745.         WA_PubScreenFallBack,    FALSE,
  746.         TAG_DONE))){
  747.         FreeGadgets(palcon);
  748.         palcon=NULL;
  749.         return;
  750.     }
  751.     for( i= REDGAD; i<=BLUEGAD; i++) DrawBevelBox( palwin->RPort , gad[ i ]->LeftEdge -4 , gad[ i ]->TopEdge-2 , gad[ i ]->Width+8 , gad[ i ]->Height+4, GT_VisualInfo,vi,TAG_END);
  752.     DrawBevelBox( palwin->RPort, palette.ng_LeftEdge-1    , palette.ng_TopEdge , 50 + 2                , palette.ng_Height , GT_VisualInfo,vi,GTBB_Recessed,TRUE,TAG_END);
  753.     DrawBevelBox( palwin->RPort, palette.ng_LeftEdge+59 -1, palette.ng_TopEdge , palette.ng_Width-59+2 , palette.ng_Height , GT_VisualInfo,vi,TAG_END);
  754.     GT_SetGadgetAttrs( gad[ PALGAD ] , palwin , NULL , GTPA_Color , 1 , TAG_END );
  755.         getcolor( 1 , screen);
  756. }
  757.  
  758. VOID
  759. ClosePalette( VOID )
  760. {
  761.     if( palwin ){
  762.         struct  IntuiMessage *m;
  763.         while( m=GT_GetIMsg( palwin->UserPort ) ) GT_ReplyIMsg( m );
  764.                    CloseWindow( palwin );
  765.         if( palcon )    FreeGadgets( palcon );
  766.         palwin = NULL;
  767.         palcon = NULL;
  768.     }
  769. }
  770.  
  771. VOID
  772. getcolor(WORD index, struct Screen *s)
  773. {
  774.     UWORD col;
  775.  
  776.     col = GetRGB4( s->ViewPort.ColorMap , index );
  777.     b = (UWORD)  (col & (0x000f));
  778.     g = (UWORD) ((col & (0x00f0)) >> 4);
  779.     r = (UWORD) ((col & (0x0f00)) >> 8);
  780.  
  781.       if(palwin){
  782.             GT_SetGadgetAttrs(gad[REDGAD]  ,palwin,NULL,GTSL_Level,r,TAG_DONE);
  783.                GT_SetGadgetAttrs(gad[GREENGAD],palwin,NULL,GTSL_Level,g,TAG_DONE);
  784.             GT_SetGadgetAttrs(gad[BLUEGAD] ,palwin,NULL,GTSL_Level,b,TAG_DONE);
  785.     }
  786. }
  787.  
  788. WORD
  789. hex2c(WORD hex)
  790. {
  791.     if(hex < 10 ) return(hex+48);
  792.         return(hex+65-10);
  793. }
  794.  
  795. WORD
  796. c2hex(WORD c)
  797. {
  798.     c=ToUpper(c);
  799.     if( (WORD)c > 64 )    return(c-65+10);
  800.     return((WORD)(c-48));
  801. }
  802.  
  803.  
  804.  
  805.  
  806. VOID
  807. About( VOID )
  808. {
  809.     WORD    count;
  810.     struct    PubScreenNode    *pubnode;
  811.     struct    List        *publist;
  812.     struct    EasyStruct    easyinfo  = {sizeof(struct EazyStruct),0,"PublicManager", "PublicManager V1.2 © 1992 by Michael Watzl\n\nWritten by:\n   Michael Watzl\n   Konradstr. 11\n   8850 Donauwoerth\n       GERMANY\n\nDefaultPubScreen: %s\nVisitors on this screen : %ld\n" ,"OK"}; /* Easy Reqs */
  813.  
  814.     if(!( publist = LockPubScreenList() )){
  815.         usermessage("Can't lock pubscreenlist!");
  816.         return;
  817.     }
  818.     pubnode = (struct PubScreenNode *)(publist->lh_Head);
  819.     while( pubnode != NULL )
  820.     {
  821.                 if( pubnode->psn_Screen == screen ) count=pubnode->psn_VisitorCount;
  822.             pubnode = pubnode->psn_Node.ln_Succ;
  823.     }
  824.     UnlockPubScreenList();
  825.  
  826.     s = LockPubScreen( NULL );
  827.     EasyRequest( screen->FirstWindow , &easyinfo , NULL, s->Title , count-1 );
  828.     UnlockPubScreen( NULL , s );
  829. }
  830.  
  831. VOID
  832. Update( VOID )
  833. {
  834.         sc.PubMode=NULL;
  835.     if( pop_mitem->Flags & CHECKED ) sc.PubMode  = POPPUBSCREEN;
  836.     if( sha_mitem->Flags & CHECKED ) sc.PubMode |= SHANGHAI;
  837.  
  838.     SetPubScreenModes( sc.PubMode );
  839.     s=LockPubScreen( NULL );
  840.     if( def_mitem->Flags & CHECKED ){
  841.         if( s != screen )    SetDefaultPubScreen( screen->Title );
  842.                 sc.Default=TRUE;
  843.         } else    if( s == screen )    SetDefaultPubScreen( "Workbench" );
  844.     UnlockPubScreen( NULL, s );
  845. }
  846.  
  847. LONG
  848. pix( STRPTR text)                    /* calc width of text */
  849. {
  850.         TextExtent( &(screen->RastPort) , text , strlen(text) , &textextent );
  851.     return( textextent.te_Width );
  852. }
  853.  
  854. VOID
  855. SetScreenColors( VOID )
  856. {
  857.     WORD j;
  858.  
  859.     if( strlen(ColorChars) > 48 ) return;
  860.     for( j=0 ; j< 16 ; j++ ){
  861.             colors[j].ColorIndex    =j;
  862.             colors[j].Red    =c2hex( (WORD)ColorChars[j*3+0] );
  863.             colors[j].Green    =c2hex( (WORD)ColorChars[j*3+1] );
  864.             colors[j].Blue    =c2hex( (WORD)ColorChars[j*3+2] );
  865.     }
  866.     colors[ j ].ColorIndex=-1;
  867. }
  868.  
  869. VOID
  870. CloseWin( VOID )
  871. {
  872.     struct  IntuiMessage *m;
  873.     while( m=GT_GetIMsg( window->UserPort ) )    GT_ReplyIMsg( m );
  874.  
  875.     if( menu ){
  876.         ClearMenuStrip( window );
  877.         FreeMenus( menu );
  878.         if( toolsmenu ) FreeMenus( toolsmenu );
  879.     }
  880.     if( window )        CloseWindow( window );
  881.  
  882.     menu    = NULL;
  883.     window    = NULL;
  884. }
  885.  
  886. VOID
  887. OpenWin( VOID )
  888. {
  889.     WORD    i,j;
  890.     BPTR    fh;
  891.  
  892.     struct NewMenu PubMenu[] = {
  893. /* 0 */        {NM_TITLE, "Project",        NULL,0,0,NULL        },
  894.         {NM_ITEM , "Backdrop",        "B" ,CHECKIT | MENUTOGGLE ,0,MENU_PROJ_BACKDROP},
  895.         {NM_ITEM , "Update Screen",    "U" ,0,0,MENU_PROJ_UPSCREEN},
  896.         {NM_ITEM , "Update Modes",    "M" ,0,0,MENU_PROJ_UPMODES},
  897.             {NM_ITEM , "Palette...",    "P" ,0,0,MENU_PROJ_PALETTE},
  898.         {NM_ITEM , "About...",        "A" ,0,0,MENU_PROJ_ABOUT},
  899.         {NM_ITEM , "Save Prefs",        "S" ,0,0,MENU_PROJ_SAVE },
  900.         {NM_ITEM , NM_BARLABEL,        NULL,0,0,NULL        },
  901.         {NM_ITEM , "Quit",        "Q" ,0,0,MENU_PROJ_QUIT    },
  902.  
  903.         {NM_TITLE, "Preferences",    NULL,0,0,NULL        },
  904. /* 10 */    {NM_ITEM , "Default PubScreen",    NULL,CHECKIT | MENUTOGGLE ,0,MENU_MODE_DEFAULT    },
  905.         {NM_ITEM , "Shanghai",        NULL,CHECKIT | MENUTOGGLE ,0,MENU_MODE_SHANGHAI    },
  906.         {NM_ITEM , "Pop to front",    NULL,CHECKIT | MENUTOGGLE ,0,MENU_MODE_POPUP    },
  907.         {NM_ITEM , NM_BARLABEL,        NULL,0,0,NULL        },
  908.         {NM_ITEM , "Screen Modes",    NULL, 0 ,0,NULL        },
  909.         {NM_SUB  , "NTSC:Hires",        NULL,CHECKIT , ~1 , MENU_MODE_NTSCHIRES    },
  910.         {NM_SUB  , "NTSC:Hires-Interlaced",    NULL,CHECKIT , ~2 , MENU_MODE_NTSCHIRESLACE},
  911.         {NM_SUB  , "PAL:Hires",            NULL,CHECKIT , ~4 , MENU_MODE_PALHIRES    },
  912.         {NM_SUB  , "PAL:Hires-Interlaced",    NULL,CHECKIT , ~8 , MENU_MODE_PALHIRESLACE    },
  913.         {NM_SUB  , "Productivity",        NULL,CHECKIT , ~16, MENU_MODE_PRODUCTIVITY    },
  914. /* 20 */    {NM_SUB  , "Custom..." ,        NULL,CHECKIT , ~32, MENU_MODE_CUSTOM        }
  915.         {NM_ITEM , "Overscan",          NULL, 0 , 0 , NULL        },
  916.         {NM_SUB  , "No Overscan",    NULL, CHECKIT , ~1 , MENU_MODE_NOOSCAN   },
  917.         {NM_SUB  , "Text",        NULL, CHECKIT , ~2 , MENU_MODE_TEXTOSCAN },
  918.         {NM_SUB  , "Standard",        NULL, CHECKIT , ~4 , MENU_MODE_STDOSCAN  },
  919.         {NM_ITEM , "Depth",        NULL, 0 , 0 , NULL        },
  920.         {NM_SUB  , " 2 Colors",        NULL, CHECKIT , ~1 , MENU_MODE_DEPTH1    },
  921.         {NM_SUB  , " 4 Colors",        NULL, CHECKIT , ~2 , MENU_MODE_DEPTH2    },
  922.         {NM_SUB  , " 8 Colors",        NULL, CHECKIT , ~4 , MENU_MODE_DEPTH3    },
  923.         {NM_SUB  , "16 Colors",        NULL, CHECKIT , ~8 , MENU_MODE_DEPTH4    },
  924. /* 30 */    {NM_ITEM , "Font",        NULL, 0 , 0 , NULL        },
  925.         {NM_SUB  , "Workbench",        NULL, CHECKIT , ~2 , MENU_MODE_WBFONT    },
  926.         {NM_SUB  , "Topaz 8",        NULL, CHECKIT , ~4 , MENU_MODE_TOPAZ    },
  927.         {NM_SUB  , "Open Disk Font...", "F" , CHECKIT , ~8 , MENU_MODE_DISKFONT    },
  928.         {NM_ITEM , "Screensize...",     NULL, 0,0,           MENU_MODE_SIZE    },
  929.  
  930.         {NM_END}
  931.     };
  932.     struct IBox    AltCoords = { 0 , screen->BarHeight+1, 200 , screen->BarHeight };
  933.     struct TagItem windowtag[] ={
  934.         WA_Top,            screen->BarHeight+1,
  935.         WA_Height,        screen->Height - screen->BarHeight-1,
  936.         WA_IDCMP,        IDCMP_MENUPICK ,
  937.         WA_PubScreen,        screen,
  938.         WA_PubScreenFallBack,    FALSE,
  939.         WA_Flags,        WFLG_ACTIVATE,
  940.                 WA_MouseQueue,        2,
  941.                 TAG_IGNORE,        &AltCoords,
  942.         WA_MinWidth,        100,
  943.         WA_MinHeight,        screen->BarHeight,
  944.         WA_Title,        &VersTag[1],
  945.         TAG_END
  946.     };
  947.     if(sc.Backdrop){
  948.                 PubMenu[1].nm_Flags    |=CHECKED;
  949.         windowtag[ 5 ].ti_Data |= WFLG_BORDERLESS | WFLG_BACKDROP;
  950.         windowtag[10 ].ti_Tag    = TAG_IGNORE;
  951.     } else {
  952.         windowtag[ 2 ].ti_Data |= IDCMP_CLOSEWINDOW;
  953.         windowtag[ 5 ].ti_Data |= WFLG_CLOSEGADGET | WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET;
  954.         windowtag[ 7 ].ti_Tag   = WA_Zoom;
  955.     }
  956.  
  957.     if(!( window = OpenWindowTagList( NULL, windowtag )))    quit("Can't open window");
  958.  
  959.         if( sc.Default  ) PubMenu[  10 ].nm_Flags |= CHECKED;
  960.         if( sc.PubMode & SHANGHAI     == SHANGHAI     ) PubMenu[ 11 ].nm_Flags |= CHECKED;
  961.         if( sc.PubMode & POPPUBSCREEN == POPPUBSCREEN ) PubMenu[ 12 ].nm_Flags |= CHECKED;
  962.  
  963.         if( sc.DisplayID == (NTSC_MONITOR_ID | HIRES_KEY )    ) PubMenu[15].nm_Flags |= CHECKED;
  964.     else    if( sc.DisplayID == (NTSC_MONITOR_ID | HIRESLACE_KEY)    ) PubMenu[16].nm_Flags |= CHECKED;
  965.     else    if( sc.DisplayID == (PAL_MONITOR_ID  | HIRES_KEY )    ) PubMenu[17].nm_Flags |= CHECKED;
  966.     else    if( sc.DisplayID == (PAL_MONITOR_ID  | HIRESLACE_KEY )    ) PubMenu[18].nm_Flags |= CHECKED;
  967.     else    if( sc.DisplayID == (VGA_MONITOR_ID  | VGAPRODUCT_KEY )    ) PubMenu[19].nm_Flags |= CHECKED;
  968.      else    PubMenu[20].nm_Flags |= CHECKED;
  969.  
  970.     PubMenu[ 22 + sc.Overscan ].nm_Flags |= CHECKED;
  971.     PubMenu[ 26 + sc.Depth -1 ].nm_Flags |= CHECKED;
  972.         PubMenu[ 31 + sc.Font     ].nm_Flags |= CHECKED;
  973.  
  974.     if( sc.Tools == TRUE ){
  975.         if(!( fh = Open ( FileName , MODE_OLDFILE ))) goto notool;
  976.         toolnm[0].nm_Type  = NM_TITLE;
  977.         toolnm[0].nm_Label = "Tools";
  978.         while( FGets( fh , Tool[ j ] , 63 )){
  979.             Tool[ j ][ strlen( Tool[ j ] ) -1]='\0';
  980.             toolnm[ j+1 ].nm_Type     = NM_ITEM;
  981.             toolnm[ j+1 ].nm_Label    = FilePart( Tool[j] );
  982.             toolnm[ j+1 ].nm_UserData = (APTR)(MENU_TOOLS_BASE+j);
  983.             if( ++j == TOOLNUM-2) break;
  984.         }
  985.         Close( fh );
  986.         toolnm[ j+1 ].nm_Type = NM_END;
  987.         toolsmenu = CreateMenus( toolnm , TAG_END);
  988.     }
  989. notool:    menu = CreateMenus(PubMenu,TAG_END);
  990.     menu->NextMenu->NextMenu=toolsmenu;
  991.     LayoutMenus( menu , vi , TAG_END);
  992.  
  993.     SetMenuStrip( window , menu );
  994.  
  995.     def_mitem = menu->NextMenu->FirstItem;
  996.         sha_mitem = menu->NextMenu->FirstItem->NextItem;
  997.         pop_mitem = menu->NextMenu->FirstItem->NextItem->NextItem;
  998.  
  999.     if( (sc.DisplayID & VGA_MONITOR_ID) == VGA_MONITOR_ID ){
  1000.         OffMenu( window , 4289 ); /* Binary: SSSSSIIIIIIMMMMM S=Sub I=Item M=Menu */
  1001.         OffMenu( window , 6337 ); /* Binary: SSSSSIIIIIIMMMMM S=Sub I=Item M=Menu */
  1002.     }
  1003. }
  1004.  
  1005. VOID
  1006. ReOpen( VOID )
  1007. {
  1008.     if( CloseScr() ){
  1009.         if( OpenScr() ) return;
  1010.         quit( NULL );
  1011.     }
  1012. }
  1013.  
  1014. LONG
  1015. GetCustomID( VOID )
  1016. {
  1017.     LONG id=-2;
  1018.     BOOL leave=FALSE;
  1019.     struct Gadget        *idcon, *gad[3];
  1020.     struct Window       *idwin;
  1021.     struct IntuiMessage     *message;
  1022.  
  1023.     struct NewGadget text     = { (30+pix("   CANCEL   ")*2 - pix("WW0x00000000WW"))/2 , FHEIGHT*3 , pix("WW0x00000000WW")     , FHEIGHT*1+5   , "_Enter DisplayID",screen->Font, 0 , PLACETEXT_ABOVE | NG_HIGHLABEL , vi , NULL};
  1024.     struct NewGadget ok     = { 10                       , FHEIGHT*5 , pix("   CANCEL   ")   , FHEIGHT+5   , "_USE"              ,screen->Font, 1 , PLACETEXT_IN    , vi , NULL};
  1025.     struct NewGadget cancel  = { 20 + pix("   CANCEL   ") , FHEIGHT*5 , pix("   CANCEL   ")   , FHEIGHT+5   , "_CANCEL"           ,screen->Font, 2 , PLACETEXT_IN    , vi , NULL};
  1026.  
  1027.     sprintf( temp , "0x%08lx", screen->ViewPort.ColorMap->VPModeID );
  1028.     if(!( idcon    = CreateContext((struct Gadget **)&idcon)))                                                                  leave=TRUE;
  1029.     if(!( gad[ 0 ] = CreateGadget(STRING_KIND , idcon    ,&text   , GT_Underscore,'_' , GTST_String, temp , GTST_MaxChars, 10 , TAG_END )))       leave=TRUE;
  1030.     if(!( gad[ 1 ] = CreateGadget(BUTTON_KIND , gad[ 0 ] ,&ok     , GT_Underscore,'_' , TAG_END )))                                          leave=TRUE;
  1031.     if(!( gad[ 2 ] = CreateGadget(BUTTON_KIND , gad[ 1 ] ,&cancel , GT_Underscore,'_' , TAG_END )))                                          leave=TRUE;
  1032.     if(leave==TRUE){
  1033.         FreeGadgets(idcon);
  1034.         idcon=NULL;
  1035.         return(-1);
  1036.     }
  1037.     if(!( idwin = OpenWindowTags( NULL,
  1038.         WA_Left            , 50 ,
  1039.                 WA_Top            , 30 ,
  1040.                 WA_Width        ,(30+pix("   CANCEL   ")*2),
  1041.                 WA_Height        ,FHEIGHT*7,
  1042.                 WA_Flags        , WFLG_ACTIVATE | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_RMBTRAP,
  1043.                 WA_IDCMP        , STRINGIDCMP | BUTTONIDCMP | IDCMP_VANILLAKEY | IDCMP_CLOSEWINDOW ,
  1044.         WA_Title        ,"Public Manager Request",
  1045.         WA_Gadgets        ,idcon,
  1046.         WA_PubScreen,        screen,
  1047.         WA_PubScreenFallBack,    FALSE,
  1048.         TAG_END))){
  1049.         FreeGadgets(idcon);
  1050.                 idcon=NULL;
  1051.                 return(-1);
  1052.         }
  1053.     ActivateGadget( gad[ 0 ] , idwin , NULL );
  1054.         while( id==-2 ){
  1055.             Wait(1<<idwin->UserPort->mp_SigBit);
  1056.             while( message = GT_GetIMsg( idwin->UserPort ) ){
  1057.                         switch( message->Class ){
  1058.                 case IDCMP_GADGETUP:
  1059.                     if( ((struct Gadget *)message->IAddress)->GadgetID == 1 )    id = ahex2ulong( ((struct StringInfo *)gad[0]->SpecialInfo)->Buffer );
  1060.                 if( ((struct Gadget *)message->IAddress)->GadgetID == 2 )    id = -1;
  1061.                 break;
  1062.                 case IDCMP_CLOSEWINDOW:
  1063.                 id = -1;
  1064.                 break;
  1065.             case IDCMP_VANILLAKEY:
  1066.                 if( message->Code == 'u') id = ahex2ulong( ((struct StringInfo *)gad[0]->SpecialInfo)->Buffer );
  1067.                 if( message->Code == 'c') id = -1;
  1068.                 if( message->Code == 'e') ActivateGadget( gad[0] , idwin , NULL);
  1069.                 break;
  1070.             }
  1071.             GT_ReplyIMsg( message );
  1072.         }
  1073.     }
  1074.     CloseWindow( idwin );
  1075.     FreeGadgets( idcon );
  1076.     return( id );
  1077. }
  1078.  
  1079. ULONG
  1080. ahex2ulong( STRPTR ahex )
  1081. {
  1082.     ULONG     id=0, x=1;
  1083.     WORD    i;
  1084.  
  1085.          for(i=9;i>1;i--){
  1086.               id+= x * c2hex( ahex[i] );
  1087.         x*=16;
  1088.     }
  1089.     return( id );
  1090. }
  1091.  
  1092.  
  1093. LONG    /* upper nibble: X Size, lower nibble: YSize: 0xXXXXYYYY */
  1094. GetNewSize( VOID )
  1095. {
  1096.     LONG Size = -1;
  1097.     WORD    wwidth;
  1098.     WORD    cwidth;
  1099.     BOOL leave=FALSE;
  1100.     struct Gadget        *sizecon, *gad[6];
  1101.     struct Window       *sizewin;
  1102.     struct IntuiMessage     *message;
  1103.  
  1104.         cwidth = pix("CANCEL");
  1105.     wwidth = 50 + 4* (pix("CANCEL")+20) ;
  1106.     struct NewGadget sizex     = { cwidth+40                       , FHEIGHT*2 , pix("WWWW")+20   , FHEIGHT*1+5  , "_Width"  , screen->Font , 0 , PLACETEXT_RIGHT , vi , NULL};
  1107.     struct NewGadget sizey     = { cwidth+40                       , FHEIGHT*4 , sizex.ng_Width   , FHEIGHT*1+5  , "_Height" , screen->Font , 1 , PLACETEXT_RIGHT , vi , NULL};
  1108.     struct NewGadget ok     = { 10                              , FHEIGHT*6 , cwidth+20        , FHEIGHT+5    , "_OK"     , screen->Font , 2 , PLACETEXT_IN    , vi , NULL};
  1109.     struct NewGadget cancel  = { wwidth - 10 - ok.ng_Width       , FHEIGHT*6 , cwidth+20        , FHEIGHT+5    , "_CANCEL" , screen->Font , 3 , PLACETEXT_IN    , vi , NULL};
  1110.     struct NewGadget wb      = { ok.ng_LeftEdge+ok.ng_Width+10   , FHEIGHT*6 , cwidth+20        , FHEIGHT+5    , "_Get WB" , screen->Font , 4 , PLACETEXT_IN    , vi , NULL};
  1111.     struct NewGadget std     = { ok.ng_LeftEdge+ok.ng_Width*2+20 , FHEIGHT*6 , cwidth+20        , FHEIGHT+5    , "_STD"    , screen->Font , 5 , PLACETEXT_IN    , vi , NULL};
  1112.  
  1113.     if(!( sizecon  = CreateContext((struct Gadget **)&sizecon)))                                              leave=TRUE;
  1114.     if(!( gad[ 0 ] = CreateGadget(INTEGER_KIND , sizecon  ,&sizex  , GT_Underscore,'_' , GTIN_MaxChars, 5 , GTIN_Number , screen->Width  , TAG_END ))) leave=TRUE;
  1115.     if(!( gad[ 1 ] = CreateGadget(INTEGER_KIND , gad[ 0 ] ,&sizey  , GT_Underscore,'_' , GTIN_MaxChars, 5 , GTIN_Number , screen->Height , TAG_END ))) leave=TRUE;
  1116.     if(!( gad[ 2 ] = CreateGadget(BUTTON_KIND  , gad[ 1 ] ,&ok     , GT_Underscore,'_' , TAG_END )))                    leave=TRUE;
  1117.     if(!( gad[ 3 ] = CreateGadget(BUTTON_KIND  , gad[ 2 ] ,&cancel , GT_Underscore,'_' , TAG_END )))                    leave=TRUE;
  1118.     if(!( gad[ 4 ] = CreateGadget(BUTTON_KIND  , gad[ 3 ] ,&wb     , GT_Underscore,'_' , TAG_END )))                    leave=TRUE;
  1119.     if(!( gad[ 5 ] = CreateGadget(BUTTON_KIND  , gad[ 4 ] ,&std    , GT_Underscore,'_' , TAG_END )))                    leave=TRUE;
  1120.  
  1121.     if(leave==TRUE){
  1122.         FreeGadgets(sizecon);
  1123.         return(0);
  1124.     }
  1125.  
  1126.     if(!( sizewin = OpenWindowTags( NULL,
  1127.         WA_Left            , 50 ,
  1128.                 WA_Top            , 50 ,
  1129.                 WA_Width        , wwidth ,
  1130.                 WA_Height        , FHEIGHT*8+4,
  1131.                 WA_Flags        , WFLG_ACTIVATE | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_RMBTRAP,
  1132.                 WA_IDCMP        , STRINGIDCMP | BUTTONIDCMP | IDCMP_VANILLAKEY | IDCMP_CLOSEWINDOW ,
  1133.         WA_Title        , "Public Manager Request",
  1134.         WA_Gadgets        , sizecon,
  1135.         WA_PubScreen,        screen,
  1136.         WA_PubScreenFallBack,    FALSE,
  1137.         TAG_END))){
  1138.         FreeGadgets(sizecon);
  1139.                 return(0);
  1140.         }
  1141.     ActivateGadget( gad[ 0 ] , sizewin , NULL );
  1142.         while( leave == FALSE ){
  1143.             Wait(1<<sizewin->UserPort->mp_SigBit);
  1144.             while( message = GT_GetIMsg( sizewin->UserPort ) ){
  1145.                         switch( message->Class ){
  1146.                 case IDCMP_GADGETUP:
  1147.                 switch( ((struct Gadget *)message->IAddress)->GadgetID ){
  1148.                     case 2:    goto getsize;
  1149.                 case 3:    leave=TRUE;
  1150.                     break;
  1151.                 case 4:
  1152. getwbsize:                if( s = LockPubScreen("Workbench")){
  1153.                         GT_SetGadgetAttrs( gad[ 0 ] , sizewin , NULL , GTIN_Number , s->Width  , TAG_END );
  1154.                         GT_SetGadgetAttrs( gad[ 1 ] , sizewin , NULL , GTIN_Number , s->Height , TAG_END );
  1155.                                                 UnlockPubScreen( NULL , s );
  1156.                                         }
  1157.                     break;
  1158.                 case 5:
  1159. getstdsize:                             switch( sc.Overscan ){
  1160.                     case NULL:
  1161.                         wwidth = dimensioninfo.Nominal.MaxX+1;
  1162.                         cwidth = dimensioninfo.Nominal.MaxY+1;
  1163.                         break;
  1164.                     case OSCAN_TEXT:
  1165.                         wwidth = dimensioninfo.TxtOScan.MaxX+1;
  1166.                         cwidth = dimensioninfo.TxtOScan.MaxY+1;
  1167.                         break;
  1168.                     case OSCAN_STANDARD:
  1169.                         wwidth = dimensioninfo.StdOScan.MaxX+1;
  1170.                         cwidth = dimensioninfo.StdOScan.MaxY+1;
  1171.                         break;
  1172.                                         }
  1173.                     GT_SetGadgetAttrs( gad[0] , sizewin , NULL , GTIN_Number , wwidth , TAG_END );
  1174.                                         GT_SetGadgetAttrs( gad[1] , sizewin , NULL , GTIN_Number , cwidth , TAG_END );
  1175.                     break;
  1176.                                 }
  1177.                 break;
  1178.                 case IDCMP_CLOSEWINDOW:
  1179.                 leave=TRUE;
  1180.                 break;
  1181.             case IDCMP_VANILLAKEY:
  1182.                 switch( message->Code){
  1183.                 case 'w':    ActivateGadget( gad[0] , sizewin , NULL);
  1184.                                                 break;
  1185.                 case 'h':    ActivateGadget( gad[1] , sizewin , NULL);
  1186.                         break;
  1187.                 case 'o':
  1188. getsize:                    Size  =   ((struct StringInfo *)gad[ 1 ]->SpecialInfo)->LongInt ;
  1189.                         Size |= ( ((struct StringInfo *)gad[ 0 ]->SpecialInfo)->LongInt ) << 16;
  1190.                         leave = TRUE;
  1191.                         break;
  1192.                 case 'c':    leave=TRUE;
  1193.                         break;
  1194.                 case 'g':    goto getwbsize;
  1195.                                 case 's':    goto getstdsize;
  1196.                 }
  1197.                 break;
  1198.             }
  1199.             GT_ReplyIMsg( message );
  1200.         }
  1201.     }
  1202.     CloseWindow( sizewin );
  1203.     FreeGadgets( sizecon );
  1204.     return( Size );
  1205. }
  1206.